home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / Libraries / WASTE 1.1a4 / Demo Source / WEDemoInit.p < prev    next >
Encoding:
Text File  |  1994-11-13  |  3.0 KB  |  124 lines  |  [TEXT/PJMM]

  1. unit DemoInit;
  2.  
  3. { WASTE DEMO PROJECT: }
  4. { Initialization & Finalization Routines }
  5.  
  6. { Copyright © 1993-1994 Merzwaren }
  7. { All Rights Reserved }
  8.  
  9. interface
  10.     uses
  11.         DemoIntf;
  12.  
  13.     function Initialize: OSErr;
  14.     procedure Finalize;
  15.  
  16. implementation
  17.     uses
  18.         DemoEvents, DemoMenus, DemoWindows, DemoPictures, DemoDrags, TextServices;
  19.  
  20.     function Initialize: OSErr;
  21.  
  22.         const
  23.             kMinSystemVersion = $700;
  24.             kScrapThreshold = 4 * 1024;
  25.  
  26.         var
  27.             response: LongInt;
  28.             scrapResult: LongInt;
  29.  
  30.         procedure CheckErr (err: OSErr);
  31.         begin
  32.             if (err <> noErr) then
  33.                 begin
  34.                     Initialize := err;
  35.                     ErrorAlert(err);
  36.                     Exit(Initialize);
  37.                 end;
  38.         end;  { CheckErr }
  39.  
  40.     begin
  41.         Initialize := noErr;
  42.  
  43. { expand the zone to its maximum size }
  44.         MaxApplZone;
  45.  
  46. { allocate some extra master pointer blocks }
  47.         MoreMasters;
  48.         MoreMasters;
  49.         MoreMasters;
  50.         MoreMasters;
  51.  
  52. { initialize the Toolbox }
  53.         InitGraf(@thePort);
  54.         InitFonts;
  55.         InitWindows;
  56.         InitMenus;
  57.         TEInit;
  58.         InitDialogs(nil);
  59.         InitCursor;
  60.         FlushEvents(everyEvent, 0);
  61.  
  62. { if desk scrap is too large, unload it }
  63.         if (InfoScrap^.scrapSize > kScrapThreshold) then
  64.             scrapResult := UnloadScrap;
  65.  
  66. { make sure system software version is 7.0 or newer }
  67.         if (Gestalt(gestaltSystemVersion, response) <> noErr) | (response < kMinSystemVersion) then
  68.             begin
  69.                 SetCursor(arrow);
  70.                 response := Alert(kAlertNeedSys7, nil);
  71.                 Initialize := -1;
  72.                 Exit(Initialize);
  73.             end;
  74.  
  75. { determine whether Color QuickDraw is available }
  76.         gHasColorQD := (Gestalt(gestaltQuickDrawVersion, response) = noErr) & (response >= gestalt8BitQD);
  77.  
  78. { determine whether the Drag Manager is available }
  79.         gHasDragAndDrop := (Gestalt(gestaltDragMgrAttr, response) = noErr) & BTST(response, gestaltDragMgrPresent);
  80.  
  81. { determine whether the Text Services Manager is available }
  82.         gHasTextServices := (Gestalt(gestaltTSMgrVersion, response) = noErr);
  83.  
  84. { register this application with the TSM }
  85.         if (gHasTextServices) then
  86.             CheckErr(InitTSMAwareApplication);
  87.  
  88. { install default drag handlers }
  89.         if (gHasDragAndDrop) then
  90.             begin
  91.                 CheckErr(InstallTrackingHandler(@MyTrackingHandler, nil, nil));
  92.                 CheckErr(InstallReceiveHandler(@MyReceiveHandler, nil, nil));
  93.             end;
  94.  
  95. { install the handlers for PICT objects }
  96.         CheckErr(WEInstallObjectHandler(kTypePicture, weNewHandler, @HandleNewPicture));
  97.         CheckErr(WEInstallObjectHandler(kTypePicture, weDisposeHandler, @HandleDisposePicture));
  98.         CheckErr(WEInstallObjectHandler(kTypePicture, weDrawHandler, @HandleDrawPicture));
  99.  
  100. { perform other initialization chores }
  101.         CheckErr(InitializeEvents);
  102.         CheckErr(InitializeMenus);
  103.  
  104.     end;  { Initialize }
  105.  
  106.     procedure Finalize;
  107.     begin
  108.  
  109. { remove drag handlers }
  110.         if (gHasDragAndDrop) then
  111.             begin
  112.                 if (RemoveTrackingHandler(@MyTrackingHandler, nil) <> noErr) then
  113.                     ;
  114.                 if (RemoveReceiveHandler(@MyReceiveHandler, nil) <> noErr) then
  115.                     ;
  116.             end;
  117.  
  118. { notify text services that we're closing down }
  119.         if (gHasTextServices) then
  120.             if (CloseTSMAwareApplication <> noErr) then
  121.                 ;
  122.     end;  { Finalize }
  123.  
  124. end.